(use-modules
 ;; SRFI 64 for unit testing facilities
 (srfi srfi-64)
 ;; csv-utils - the code to be tested
 (utils csv)
 (utils os))


(test-begin "csv-utils")


(test-group
 "all-rows"

 (test-equal "all-rows-1"
   (list #("2.771244718" "1.784783929" "0")
         #("1.728571309" "1.169761413" "0")
         #("3.678319846" "2.81281357" "0")
         #("3.961043357" "2.61995032" "0")
         #("2.999208922" "2.209014212" "0")
         #("7.497545867" "3.162953546" "1")
         #("9.00220326" "3.339047188" "1")
         #("7.444542326" "0.476683375" "1")
         #("10.12493903" "3.234550982" "1")
         #("6.642287351" "3.319983761" "1"))

   (all-rows
    (path-join "test" "resources" "csv-with-leading-and-trailing-whitespace.csv")
    #:converters
    (list (list (lambda (val) (string-trim-both val char-set:whitespace)))
          (list (lambda (val) (string-trim-both val char-set:whitespace)))
          (list (lambda (val) (string-trim-both val char-set:whitespace))))))

 (test-equal "all-rows-2"
   (list #(-2.771244718 "1.784783929" "0")
         #(-1.728571309 "1.169761413" "0")
         #(-3.678319846 "2.81281357" "0")
         #(-3.961043357 "2.61995032" "0")
         #(-2.999208922 "2.209014212" "0")
         #(-7.497545867 "3.162953546" "1")
         #(-9.00220326 "3.339047188" "1")
         #(-7.444542326 "0.476683375" "1")
         #(-10.12493903 "3.234550982" "1")
         #(-6.642287351 "3.319983761" "1"))

   (all-rows
    (path-join "test" "resources" "csv-with-leading-and-trailing-whitespace.csv")
    #:converters
    (list (list (lambda (val) (string-trim-both val char-set:whitespace))
                string->number
                (lambda (num) (* -1 num)))
          (list (lambda (val) (string-trim-both val char-set:whitespace)))
          (list (lambda (val) (string-trim-both val char-set:whitespace)))))))

(test-group
 "read-dsv-from-file"

 (test-equal "read-dsv-from-file-1"
   '(("  2.771244718" "1.784783929" "0")
     ("1.728571309" "1.169761413" "0  ")
     ("3.678319846" "2.81281357" "0")
     ("   3.961043357" "2.61995032" "0")
     ("2.999208922" "2.209014212" "0 ")
     ("7.497545867" "3.162953546" "1")
     (" 9.00220326" "3.339047188" "1")
     ("7.444542326" "0.476683375" "1   ")
     ("10.12493903" "3.234550982" "1")
     ("  6.642287351" "3.319983761" "1"))
   (read-dsv-from-file "test/resources/csv-with-leading-and-trailing-whitespace.csv")))


(test-end "csv-utils")
